package com.vlong.town.controller.server.goods;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.vlong.town.controller.base.BaseController;
import com.vlong.town.entity.goods.GoodsInfo;
import com.vlong.town.service.goods.GoodsInfoService;
/**
 * 本地特产Rest接口Controller
 * @author Assassin
 */
@RequestMapping("/rest/goods")
@RestController
public class GoodsInfoRestController extends BaseController{
	
	@Autowired
	private  GoodsInfoService  goodsInfoService;
	
	/**
     * 查询精品商品信息
     * @param pageNo 当前页码
     * @param pageSize 每页显示记录数
     * @return List<GoodsInfo>
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public List<GoodsInfo> list(
            @PathVariable(required=true, value="pageNo") Integer pageNo,
            @PathVariable(required=true, value="pageSize") Integer pageSize) {
        PageHelper.startPage(getPageNo(pageNo), getPageSize(pageSize));
        PageHelper.orderBy("update_time DESC");
        List<GoodsInfo> GoodsInfoAList = goodsInfoService.queryList(1, null, null, null,null);
        return GoodsInfoAList;
    }
    
    
    /**
     * 小程序接口
     * 查询商品信息
     * @param pageNo 当前页码
     * @param pageSize 每页显示记录数
     * @return List<GoodsInfo>
     */
    @GetMapping("/listXcx/{type}")
    public List<GoodsInfo> listXcx(@PathVariable(required=true, value="type") Integer type) {
        List<GoodsInfo> GoodsInfoAList = goodsInfoService.queryList(type, null, null, null,null);
        for (GoodsInfo goodsInfo : GoodsInfoAList) {
        	Long createTime = goodsInfo.getCreateTime();
        	SimpleDateFormat  sdf=new  SimpleDateFormat("yyyy-MM-dd");
        	Date date = new  Date(createTime);
        	String format = sdf.format(date);
        	goodsInfo.setCreateDate(format);
		}
        return GoodsInfoAList;
    }
    
    
    /**
     * 查询本地特产信息
     * @param pageNo 当前页码
     * @param pageSize 每页显示记录数
     * @return List<GoodsInfo>
     */
    @GetMapping("/listTwo/{pageNo}/{pageSize}")
    public List<GoodsInfo> listTwo(
            @PathVariable(required=true, value="pageNo") Integer pageNo,
            @PathVariable(required=true, value="pageSize") Integer pageSize) {
        PageHelper.startPage(getPageNo(pageNo), getPageSize(pageSize));
        PageHelper.orderBy("update_time DESC");
        List<GoodsInfo> GoodsInfoAList = goodsInfoService.queryList(2, null, null, null,null);
        return GoodsInfoAList;
    }
    
    /**
     * 查询本地特产详情
     * @param id 本地特产id
     * @return GoodsInfo
     */
    @GetMapping("/detail/{id}")
    public GoodsInfo detail(@PathVariable(required=true, value="id") Long id) {
    	return goodsInfoService.queryById(id);
    }
    
	
}
